/*
 * @Descripttion: 笔记相关api
 * @Author: junhuafly
 * @Date: 2020-03-10 15:58:04
 * @LastEditors: junhuafly
 * @Email: junhuafly@163.com
 * @LastEditTime: 2020-04-21 10:32:10
 */
const {
    request
} = require('./../utils/request.js')

class Note {
    constructor() {

    }

    /**
     * 发布笔记
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    handleNote(data){
        return request[data.method](`/note${data.method==='delete'?'?noteId='+data.noteId:''}`,data)
    }


    /**
     * 获取笔记列表
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    getNotes(data) {
        const {
            pageNum
        } = data
        return request.post(data.url, {
            pageNum,
            pageSize: 10
        })
    }
    /**
     * 查询自己发布的笔记
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryNoteByMe(data){
        return request.post('/note/my',data)
    }
    /**
     * 提醒事项
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryRemind(data) {
        return request.get('/remind/my')
    }

    /**
     * 获取笔记初始化信息
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryNoteDetailInit(data) {
        return request.get('/note/init', data)
    }

    /**
     * 查看笔记带货信息
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryNoteGoods(data){
        return request.get('/note/product',data)
    }

    /**
     * 检测是否被收藏
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    checkCollect(data) {
        return request.get('/note/check/collect', data)
    }

    /**
     * 检测是否被点赞
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    checkLike(data) {
        return request.get('/note/check/like', data)
    }

    /**
     * 获取点赞列表
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryLikeList(data){
        return request.post('/note/like/list',data)
    }

    /**
     * 获取相关推荐
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryRelate(data) {
        return request.get('/note/relate', data)
    }

    /**
     * 获取评论
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryReply(data) {
        return request.post('/reply/query', data)
    }
    /**
     * 操作笔记收藏及喜欢
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    handleNoteLikeOrCollect(data) {
        const url = data.handle == 1 ? '/note/collect' : '/note/like'
        delete data.handle
        return request.get(url, data)
    }

    /**
     * 操作笔记黑名单
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    handleBlock(data){
        return request.post('/block/note',data)
    }

    /**
     * 获取收藏的笔记
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    queryByCollectNote(data){
        return request.post('/note/my/collect',data)
    }
    /**
     * 笔记操作次数
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    operateNote(data) {
        return request.get("/note/operate", data)
    }

    /**
     * 评论笔记及评论
     * 
     * @param {any} data noteId,replyContent
     * @returns 
     * 
     * @memberOf Note
     */
    replyAction(data) {
        return request.post(data.replyToId ? "/reply/sub" : "/reply", data)
    }

    /**
     * 赞评论及取消赞
     * 
     * @param {any} data replyId, type:NO or YES
     * @returns 
     * 
     * @memberOf Note
     */
    handleLikeReply(data) {
        return request.get('/reply/like', data)
    }
    /**
     * 删除评论
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    dropReply(data) {
        return request.get('/reply/delete', data)
    }

    /**
     * 获取二级评论
     * 
     * @param {any} data 
     * @returns 
     * 
     * @memberOf Note
     */
    querySubReply(data) {
        const {
            pageNum,
            replyId
        } = data
        return request.post("/reply/query/sub", {
            pageNum,
            pageSize: 10,
            replyId
        })
    }

    /**
     * 获取评论点赞前六个
     * 
     * @param {any} data replyId
     * @returns 
     * 
     * @memberOf Note
     */
    queryReplyLikeTop(data) {
        return request[data.replyId&&data.pageNum?'post':'get']("/reply/like/list", data)
    }

}

exports.noteAPI = new Note